package com.chao.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.baiwang.bop.client.ILoginClient;
import com.baiwang.bop.client.impl.PostLogin;
import com.baiwang.bop.request.impl.LoginRequest;
import com.baiwang.bop.respose.entity.LoginResponse;
import com.baiwang.open.exception.BWOpenException;

import java.util.UUID;

public class BaiWangAPIController {

    // 百望云开放平台沙箱环境地址
    private static String url = "http://openapi.baiwang.com/router/rest";
    // 百望云开放平台沙箱环境 appKey
    protected static String appKey = "10001672";
    // 百望云沙箱环境 用户名
    private static String userName = "admin_3000000526480";
    // 百望云沙箱环境 密码
    private static String password = "123qwe!@#";
    // 百望云沙箱环境 appSecret
    private static String appSecret = "a570e227-9ec0-4bff-bdc5-e0e7b7638e86";
    // 百望云沙箱环境 用户盐值
    private static String userSalt = "8668a67a9c5a4453948bfd098642ab4d";

    public static void main(String[] args) {
        try {
            //自定义请求唯一标识
            String requestId = UUID.randomUUID().toString();
            System.out.println("requestId = " + requestId);
            LoginRequest loginRequest = new LoginRequest();
            loginRequest.setAppkey("10001672");
            loginRequest.setAppSecret("a570e227-9ec0-4bff-bdc5-e0e7b7638e86");
            loginRequest.setUserName("admin_3000000526480");
            loginRequest.setPasswordMd5("123qwe!@#");
            loginRequest.setUserSalt("8668a67a9c5a4453948bfd098642ab4d");
            System.out.println("loginRequest = " + JSONObject.toJSONString(loginRequest));
            ILoginClient loginclient = new PostLogin(url);
            LoginResponse loginResponse = loginclient.login(loginRequest);
            String token = loginResponse.getAccess_token();//获取token
            System.out.printf("用户【%s】的获取的token是：%s\n", userName, token);
        } catch (BWOpenException e) {
            System.out.println(e.getCode());
        }
    }
}
